﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Vkontakte.Api.Windows
{
	/// <summary>
	/// Interaction logic for AuthorizatorWinForms.xaml
	/// </summary>
	public partial class AuthorizatorWinForms
		: UserControl, IVkApiAutorizationMethod
	{
		public AuthorizatorWinForms()
		{
			InitializeComponent();
			Auth.Authenticated += delegate
			{
			    if (Authenticated!=null)
			    {
			    	Authenticated();
			    }
			};
			Auth.NeedLoginData += delegate
			{
				if ( NeedLoginData != null )
				{
					NeedLoginData();
				}
			};
			Auth.LoginCanceled += delegate
			                      	{
			                      		if (LoginCanceled != null)
			                      		{
			                      			LoginCanceled();
			                      		}
			                      	};
		}

		public int AppID
		{
			get
			{
				return Auth.AppID;
			}
			set
			{
				Auth.AppID = value;
			}
		}

		public ApplicationAccess ApplicationAccess
		{
			get
			{
				return Auth.ApplicationAccess;
			}
			set
			{
				Auth.ApplicationAccess = value;
			}
		}

		public bool IsAuthorized
		{
			get { return Auth.IsAuthorized; }
		}

		public Session GetAuthorizationToken()
		{
			return Auth.GetAuthorizationToken();
		}

		public void Authenticate()
		{
			Auth.Authenticate();
		}

		public event Action NeedLoginData;
		public event Action Authenticated;
		public event Action LoginCanceled;
	}
}
